package com.java8.lambda.dome;


import com.java8.lambda.bean.Person;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class TestSort {
    public static void main(String[] args) {
        List<Person> persons = new ArrayList<>();
        persons.add(new Person(1, "张三", 28));
        persons.add(new Person(1, "李四", 25));
        persons.add(new Person(1, "王五", 27));

        persons.forEach((p) -> {
            System.out.println(p);
        });


        System.out.println("----------------------------------");

        persons = new ArrayList<>();
        persons.add(new Person(1, "张三", 28));
        persons.add(new Person(1, "李四", 25));
        persons.add(new Person(1, "王五", 27));


        Collections.sort(persons, (p1, p2) -> {
            if (p1.getAge() > p2.getAge()) {
                return 1;
            } else {
                return -1;
            }
        });

        persons.forEach((p) -> {
            System.out.println(p);
        });

    }
}
